<template>
	<view class="page-body">
		<view class=" bg-white text-center">
			<image class="img" mode="widthFix" :src="baseUrl+hdPic"></image>
		</view>
		<bottomShare :imgFile="baseUrl+hdPic" :url="baseUrl+hdPic"></bottomShare>
	</view>
</template>

<script>
	import bottomShare from '@/components/bottomShare';
	export default {
		components: {
			bottomShare
		},
		data() {
			return {
				baseUrl:this.config.baseUrl,
				hdPic:'',
			}
		},
		onLoad(options) {
			this.hdPic = options.hdPic;
			let data = [];
			data.imgUrl = this.config.baseUrl + this.hdPic;
			data.title = document.title;
			this.setWxShare(data);
		},
		onShow: function() {},
		computed: {},
		onReady() {},
		methods: {
			setWxShare(data) {
				var wxshare = require('./wxshare');
				this.$u.post('/member/api.users/getWxShare',{url:window.location.href}).then(res => {
					wxshare.config({
						debug: false,//是否打开调试
						appId: res.data.wxShare.appId, // 公众号的唯一标识  
						timestamp: res.data.wxShare.timestamp, // 生成签名的时间戳  
						nonceStr: res.data.wxShare.nonceStr, // ，生成签名的随机串  
						signature: res.data.wxShare.signature, // 签名  
						jsApiList: ['updateAppMessageShareData','updateTimelineShareData',]
					});
					wxshare.ready(function() {
						let links = window.location.href;
						let shareLink = ''
						if (links.indexOf('share_token') < 0){
							if (links.indexOf('?') > 0){
								shareLink = links + '&share_token=' + res.data.token; 
							}else{
								shareLink = links + '?share_token=' + res.data.token; 
							}
						}else{
							shareLink = links;
						}
						//分享给朋友
						wxshare.updateAppMessageShareData({
							title: data.title?data.title:'', // 分享标题  
							desc: data.desc?data.desc:'', // 分享描述  
							link: shareLink, // 当前页面链接  
							imgUrl: data.imgUrl?data.imgUrl:'', // 分享图标                                
							success: function() {//分享成功回调
								 
							},
							cancel: function() {//取消分享回调
							 
							}
						});
						//分享到朋友圈
						wxshare.updateTimelineShareData({
							title: data.title?data.title:'', // 分享标题
							desc: data.desc?data.desc:'', // 分享描述  
							link: shareLink, // 当前页面链接  
							imgUrl: data.imgUrl?data.imgUrl:'', // 分享图标                             
							success: function() {
							},
							cancel: function() {
							}
						});
					})
					
				})				
			},
		}
	}
</script>

<style lang="scss">
	.img{
		width: 100%;
	}
</style>
